//
//  IMManager.swift
//  Liao
//
//  Created by 范东 on 2022/3/17.
//

import Foundation
import FDFoundation

enum MessageType: Int {
    case callStart = 1001
    case callAccept = 1002
    case callRefuse = 1003
    case callEnd = 1004
}

class MessageModel: BaseModel{
    var type: Int = 0
    var callType: Int = 0
    var channelId = ""
    var desc = ""
}

class IMManager: NSObject {
    class func send(toUserId: String, message: MessageModel, success: @escaping ((String)->()), failure: @escaping ((String)->())){
        let msg = V2TIMManager.sharedInstance().createCustomMessage(message.toJSONString()?.data(using: .utf8), desc: message.desc, extension: "")
        let pushInfo = V2TIMOfflinePushInfo()
        pushInfo.title = TUILogin.getNickName()
        pushInfo.desc = message.desc
        V2TIMManager.sharedInstance().send(msg, receiver: toUserId, groupID: "", priority: .PRIORITY_DEFAULT, onlineUserOnly: true, offlinePushInfo: pushInfo) { progress in
            debugPrint("发送消息进度:\(progress)")
        } succ: {
            success("发送消息成功")
        } fail: { code, msg in
            failure(msg ?? "")
        }
    }
}
